"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FairyGUI = CS.FairyGUI;
const FairyEditor = CS.FairyEditor;
const UIWind_1 = require("./UIWind");
const ToolMgr_1 = require("../ToolMgr");
const App = FairyEditor.App;
class NodeThree extends UIWind_1.default {
    constructor() {
        super(new UIWind_1.WindData("Extend", "NodeThree"));
    }
    static show() {
        let url = ToolMgr_1.default.joinUrl("Extend", "NodeThree");
        if (UIWind_1.default.FindUrl(url) == undefined) {
            UIWind_1.default.add(new this);
        }
        super.show(url);
    }
    onInit() {
        super.onInit();
        this.three = this.contentPane.GetChild("three").asTree;
        this.close = this.contentPane.GetChild("close").asButton;
        this.sousuo = this.contentPane.GetChild("sousuo").asButton;
        this.sousuo_input = this.contentPane.GetChild("sousuo_input").asLabel;
        this.close.onClick.Add(this.onCancelClick.bind(this));
        this.three.treeNodeRender = this.renderTreeNode.bind(this);
        this.three.treeNodeWillExpand = this.onTreeNodeExpand.bind(this);
        this.sousuo.onClick.Add(this.onSousuoClick.bind(this));
    }
    onShown() {
        super.onShown();
        this.three.RemoveChildrenToPool();
        let rootNode = new CS.FairyGUI.GTreeNode(true);
        rootNode.data = App.groot;
        this.three.rootNode.AddChild(rootNode);
    }
    onHide() {
        super.onHide();
        this.three.RemoveChildrenToPool();
    }
    /**检索节点树 */
    onSousuoClick() {
        let name = this.sousuo_input.GetChild("title").text;
        if (name == "")
            return;
        let target = ToolMgr_1.default.getChildToChild(App.groot, name);
        if (target) {
            ToolMgr_1.default.Log(`找到节点:${target.name}`);
            ToolMgr_1.default.Log("路径:" + ToolMgr_1.default.getAbsPath(target));
        }
    }
    getchilds(obj) {
        return ToolMgr_1.default.getCurrentParentChild(obj);
    }
    updateThree(node) {
        let arrray = this.getchilds(node.data);
        for (let i = 0; i < arrray.length; i++) {
            if (arrray[i].name == this.windData.resName)
                continue;
            let obj = arrray[i];
            let childNode = null;
            childNode = new CS.FairyGUI.GTreeNode(this.isComponent(obj));
            childNode.data = obj;
            node.AddChild(childNode);
        }
    }
    renderTreeNode(node, index, level) {
        node.cell.text = `${node.data.name} (` + (node.data.GetType().ToString() + ")");
        node.cell.icon = ToolMgr_1.default.getIcon(node.data);
    }
    onTreeNodeExpand(node) {
        if (node.expanded)
            this.updateThree(node);
        else {
            node.RemoveChildren();
        }
    }
    onCancelClick() {
        let self = this;
        this.Hide();
        FairyGUI.Timers.inst.Add(0.05, 1, () => {
            UIWind_1.default.remove(self);
        });
    }
    //是否是组件
    isComponent(obj) {
        if (obj instanceof CS.FairyGUI.GComponent) {
            return true;
        }
        else if (obj instanceof CS.FairyGUI.GButton) {
            return true;
        }
        else if (obj instanceof CS.FairyGUI.GLabel) {
            return true;
        }
        else if (obj instanceof CS.FairyGUI.GProgressBar) {
            return true;
        }
        else if (obj instanceof CS.FairyGUI.GSlider) {
            return true;
        }
        else if (obj instanceof CS.FairyGUI.GComboBox) {
            return true;
        }
        else if (obj instanceof CS.FairyGUI.GScrollBar) {
            return true;
        }
        return false;
    }
}
exports.default = NodeThree;
